/**
 * PullRefreshTestActivity.java
 * com.jamin.PullRefreshListView
 *
 * Function： TODO 
 *
 *   ver     date      		author
 * ──────────────────────────────────
 *   		 2012-1-30 		wangjieming
 *
 * Copyright (c) 2012, TNT All Rights Reserved.
*/

package com.jamin.pullrefresh;

import com.jamin.pullrefresh.PullUpRefreshListView.OnRefreshListener;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.jamin.R;

/**
 * ClassName:PullRefreshTestActivity
 *
 * @author   wangjieming
 * @version  1.0
 * @since    v1.0
 * @Date	 2012-1-30 上午10:20:37 
 */

public class PullUpRefreshTestActivity extends Activity {
	/** Called when the activity is first created. */
	PullUpRefreshListView listview  = null;
	int size = 3;  
	


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pull_up_refresh_test_activity);

		listview = (PullUpRefreshListView) findViewById(R.id.pull_list_view);
		final MyAdapter adapter = new MyAdapter(this);
		listview.setAdapter(adapter);

		listview.setonRefreshListener(new OnRefreshListener() {  

			public void onRefresh() {  
				new Thread(new Runnable() {  
					public void run() {  

						try {  
							Thread.sleep(1000);  

						} catch (Exception e) {  

						}  

						runOnUiThread(new Runnable() {  
							public void run() {  
								adapter.notifyDataSetChanged();
								listview.onRefreshComplete(); 	
								
							}  
						});  

						size++;  

					}  
				}).start();  
			}  
		});  


	}



	class MyAdapter extends BaseAdapter{

		LayoutInflater inflater = null;

		public MyAdapter(Context ctx ){
			inflater = LayoutInflater.from(ctx);		
		}

		@Override
		public int getCount() {

			// TODO Auto-generated method stub
			return size;

		}


		@Override
		public Object getItem(int position) {

			// TODO Auto-generated method stub
			return null;

		}

		@Override
		public long getItemId(int position) {

			// TODO Auto-generated method stub
			return 0;

		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {

			View itemView = inflater.inflate(R.layout.pull_refresh_item, null);
			TextView tv = (TextView) itemView.findViewById(R.id.item_textView);
			ImageView iv = (ImageView) itemView.findViewById(R.id.item_imageView);
			tv.setText("hello");
			iv.setBackgroundResource(R.drawable.app_icon);
			// TODO Auto-generated method stub
			return itemView;

		}

	} 

}

